<?php

namespace app\api\controller\wanlshop;

use think\Log;
use app\common\controller\Api;
use app\api\model\wanlshop\Goods;

/**
 * WanlShop 回调接口
 */
class Wpsnotify extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];


    public function _initialize()
    {
        parent::_initialize();

    }

    public function index()
    {
        Log::log("wps nitify:");
        $data = request()->post();
        if (empty($data) || empty($data['type'])) {
            echo 'success';
        }
        $content = $data['c_content'] ?? [];
        switch ($data['type']) {
            case 2://2：价格变更：
                if ($content) {
                    $content = $content['goods'] ?? [];
                    foreach ($content as $value) {
                        /*{
                            "c_father_goods_id": "商品父级id",
                            "c_goods_id": "skuID",
                        }*/
                        $goods = Goods::where('c_father_goods_id', $value['c_father_goods_id'])->find();
                        if ($goods) {
                            \app\api\service\wanlshop\Common::getData('getGoodsDetails',['father_id' => $value['c_father_goods_id']]);
                            Log::log("wps notify :status change: $goods->title 价格变更");
                        }
                    }
                }
                break;
            case 4://4：上下架变更：
                if ($content) {
                    foreach ($content as $value) {
                        //c_father_goods_id: 父级编码,
                        //        msg: 商品上下架变更,
                        //        type: 4,
                        //        "state": 0 下架， 1 上架
                        $goods = Goods::where('c_father_goods_id', $value['c_father_goods_id'])->find();
                        if ($goods) {
                            $goods->status = $value['state'] == 0 ? 'hidden' : 'normal';
                            $goods->save();
                            Log::log("wps notify :status change: $goods->title 上下架变更 -- {$value['msg']}");
                        }
                    }
                }
                break;
            case 16://16：详情数据变更：
                break;
            case 28://28，售后服务单进度消息：
                break;
            case 23://23，订单配送消息：
                break;
            case 29://29，售后地址推送(退货类型的售后单如果在同意售后的时候没有返回售后地址信息，将会收到此类型消息)：
                break;
            case 30://30：已选商品推送
                break;
            case 36://36，充值订单消息推送：（status 1 成功 2 失败）
                break;
        }
        echo 'success';
    }
}
	
	
	
	